<!--管理员个人信息页面-->
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@page import="java.sql.*"%>
<%@page import="org.edu.system.DBConnect"%>
<%
	String adm_id = (String) (session.getAttribute("UserName"));
	String sql = "SELECT * FROM administrator WHERE adm_id = '" + adm_id + "'";
	System.out.println(sql);

	Connection con = DBConnect.getCon();
	Statement stmt = null;
	ResultSet rs = null;
	stmt = con.createStatement();
	rs = stmt.executeQuery(sql);//执行命令
	if (rs.next())// 如果记录集非空，表明有匹配的用户ID
	{

		//正常进行
	} else {
		// 否则登录失败
		// response.sendRedirect ( "MyJsp.jsp" );
		response.sendRedirect("login_failure.jsp");
	}
%>
<!DOCTYPE html>
<html>
<head>
<link href="./bootstrap/css/bootstrap.min.css" rel="stylesheet">
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
	<center>
	<br>
	<div class="info">
		<h4>当前管理员账户：<%=adm_id%></h4><!-- 利用上面的sessionget获取当前用户-->
		<br>
		<table border="1" class="table table-striped table-bordered">
			<tr><!-- 设置表头 -->
				<th>管理员ID</th>
				<th>管理员密码</th>
			</tr>
			<%
				PreparedStatement pst = null;
				ResultSet rs1 = null;
				try {
					String sql_select = "SELECT * FROM administrator where adm_id='"+adm_id+"'";
					Connection con1 = DBConnect.getCon();
					request.setCharacterEncoding("utf-8");
					System.out.println(sql_select);
					pst = con1.prepareStatement(sql_select);
					rs1 = pst.executeQuery();
					System.out.println(pst);
					System.out.println(rs1);//匹配并循环输出账户密码
					while (rs1.next()) {
			%>
			<tr><!-- 设置表格跟随着表头显示 -->
				<td><font size="2"><%=rs1.getString("adm_id")%></font></td>
				<td><font size="2"><%=rs1.getString("adm_passwd")%></font></td>
			</tr>
			<%
				}
				} catch (Exception e) {
					out.println(e);
				}
			%>
		</table>
	</div>
	<div class="pwchange"><!-- 设置密码 -->
		<br> <h4>修改当前密码</h4><br>
		<form action="adm_passwd.jsp" name="pasw" method="post"><!-- 将表单中数据传到adm_passwd.jsp -->
			<label for="pw1">输入新密码：</label>
			<input type="text" name="pw1" id="pw1" value="" class=“item” maxlength='32' autocomplete="off"> <br><br>
			<label for="pw2">再输入一次：</label>
			<input type="text" name="pw2" id="pw2" value="" class=“item” maxlength='32' autocomplete="off"><br><br>
			<input type="submit" value="提交" class="btn btn-primary btn-sm" onclick="return validateLogin();"><!-- 嵌入js脚本以检测两次输入密码是否一致 -->
		</form>
	</div>
	</center>
</body>
<script language="javaScript"><!-- js脚本本体 -->
	function validateLogin() {
		var pw1 = document.pasw.pw1.value;//定义pw1，从本文档的表单pasw中获取pw1的值
		var pw2 = document.pasw.pw2.value;
		if (pw1 == pw2) {
			return true;
		}
		if (pw1 != pw2) {
			alert("请输入相同密码");
			return false;
		}
	}
</script>
</html>